<!doctype html>
<html>
<head>
<meta charset="utf-8"> 
</head> 
<p id="support">你的浏览器不支持 HTML5 Web Workers</p>
<button id="stopButton" >停止任务</button>
<button id="helloButton" >发送消息</button>
<script>
window.onload = function() {
    if( typeof (Worker) !== "undefined") {
        document.getElementById("support").innerHTML = "你的浏览器支持HTML5 Web Workers";
        worker = new Worker("worker.js");
		worker.onmessage = function(e) {
		    console.log(e.data);
		}
		worker.onerror = function(e) {
		    console.warn(e.message, e);
		}		
        document.getElementById("helloButton").onclick = function() {
            worker.postMessage("ok");
        }
        document.getElementById("stopButton").onclick = function() {
            worker.terminate();
        };
    }
}

</script>
